package com.baidu.translate.demo;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Scanner;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baidu.translate.demo.TransApi;

public class translate {
	private static final String APP_ID = "20210408000767617";
    private static final String SECURITY_KEY = "UhNKsWDKoQLD9m7kAYdI";
	  public static String translate(String word) {
		  
	    	TransApi api = new TransApi(APP_ID, SECURITY_KEY);
	    	String data =api.getTransResult(word, "auto", "zh");
	    	
	    	//System.out.println(data);
	    	
	    	JSONObject object =JSONObject.parseObject(data);
	    	JSONArray array =object.getJSONArray("trans_result");
	    	JSONObject elem=JSONObject.parseObject(array.get(0).toString());
	    	String dst =elem.getString("dst");
	    	try {
	    		String value= URLDecoder.decode(dst,"utf-8");
	    		System.out.println(value);
	    	}catch(UnsupportedEncodingException e) {e.printStackTrace();}
	    	
	    	return "";
	    }
	    
}
